package com.dongdongshop.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dongdong.pojo.TbAddress;
import com.dongdong.pojo.TbUser;
import com.dongdong.service.AddressService;
import com.dongdongshop.configresult.Result;
import com.dongdongshop.em.ResultEnum;
import org.apache.shiro.SecurityUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("addressController")
public class AddressController {

    @Reference
    private AddressService addressService;

    @RequestMapping("select")
    @ResponseBody
    public Result select(){
        TbUser user = (TbUser) SecurityUtils.getSubject().getPrincipal();
//        用户名字
        String username = user.getUsername();
//        根据用户ID查询出地址表
        List<TbAddress> addressList = addressService.selectByUserId(username);
        return Result.builResult(ResultEnum.SUCCESS).setResout(addressList);
    }

    @RequestMapping("getNuam")
    @ResponseBody
    public Result getNuam(String name){
        String[] split = name.split(",");
        String provinceId = split[0];
        String cityId = split[1];
        String townId = split[2];
        System.out.println(provinceId);
        System.out.println(cityId);
        System.out.println(townId);
        return Result.builResult(ResultEnum.SUCCESS);
    }
}
